/*
 * @Author       : 魏威 <1209562577@qq.com>
 * @Date         : 2022-02-10 17:21 周4
 * @Description  :
 */

import { Table, TableProps } from "antd";
import { Pin } from "components/pin";
import dayjs from "dayjs";
import React from "react";
import { Link } from "react-router-dom";
import { Project, User } from "types";
interface ListProps extends TableProps<Project> {
  users: User[];
}

export default function List(props: ListProps) {
  const { users, ...resProps } = props;

  return (
    <Table
      pagination={false}
      columns={[
        {
          title: <Pin checked={true} />,
          render: (value, project) => (
            <Pin checked={project.pin} onCheckedChange={() => {}} />
          ),
        },
        {
          title: "名称",
          dataIndex: "name",
          sorter: (a, b) => a.name.localeCompare(b.name),
          render: (name, project) => <Link to={project.id + ""}>{name}</Link>,
        },
        {
          title: "部门",
          dataIndex: "organization",
        },
        {
          title: "负责人",
          render: (value, project) =>
            users.find((user) => user.id === Number(project.personId))?.name ||
            "未知",
        },
        {
          title: "时间",
          dataIndex: "created",
          render: (created) =>
            created ? dayjs(created).format("YYYY-MM-DD") : "无",
        },
      ]}
      rowKey={"id"}
      {...resProps}
    />
  );
}
